package me.grm.cs;

import me.grm.cs.database.TextDatabase;
import me.grm.cs.student.IStudent;
import me.grm.cs.student.StudentFactory;

import java.util.Scanner;

public class Main {
    private static final Scanner in = new Scanner(System.in);
    private static IStudent role = null;

    public static void main(String[] args) {
        TextDatabase.getInstance();
        welcomeMessage();
        handleLogin();
        work();
    }

    private static void welcomeMessage() {
        System.out.println("Welcome to the course selecting system");
        System.out.println("Could you please tell me that whether you are an undergraduate student or a postgraduate student?");
        System.out.print("1. Undergraduate\n2. Postgraduate\n");
    }

    private static void helpMessage() {
        System.out.println("Please choose functions");
        System.out.print("""
                1. List selected class
                2. Select Class
                3. Delete Class
                4. Help
                5. Quit
                """);
    }

    private static void handleLogin() {
        while(true) {
            System.out.print("Input: ");
            int choice = in.nextInt();
            if(choice >= 1 && choice <= 2) {
                role = StudentFactory.get(choice-1);
                break;
            }
            else {
                System.out.println("Invalid input. Please try again");
            }
        }
        role.login();
    }

    private static void work() {
        helpMessage();
        loop: while(true) {
            System.out.print("Input: ");
            int choice = in.nextInt();
            switch (choice) {
                case 1:
                    role.listCourse();
                    break;
                case 2:
                    role.selectCourse();
                    break;
                case 3:
                    role.deleteCourse();
                    break;
                case 4:
                    helpMessage();
                    break;
                case 5:
                    break loop;
                default:
            }
        }
    }
}
